package tracing

import (
	"io"

	"github.com/opentracing/opentracing-go"
	"github.com/openzipkin/zipkin-go"

	zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing"
	zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
)

func GetZipkinTracer(url string, serviceName string) (opentracing.Tracer, io.Closer, error) {
	reporter := zipkinhttp.NewReporter(url)

	zEP, err := zipkin.NewEndpoint(serviceName, "")
	if err != nil {
		return nil, reporter, err
	}
	zipkinTracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(zEP))
	if err != nil {
		return nil, reporter, err
	}

	return zipkinot.Wrap(zipkinTracer), reporter, nil
}
